package com.itheima.advantagesup.controller;

import com.itheima.advantagesup.common.PageBean;
import com.itheima.advantagesup.common.R;
import com.itheima.advantagesup.dto.AdvImgCreateDTO;
import com.itheima.advantagesup.dto.AdvImgPageDTO;
import com.itheima.advantagesup.dto.AdvImgUpdateDTO;
import com.itheima.advantagesup.entity.YddAdvimg;
import com.itheima.advantagesup.service.yddAdvimgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/ydd_advimg")
@Slf4j
@Api(tags = "广告图管理")
public class yddAdvimgController {

    @Autowired
    private yddAdvimgService yddAdvimgService;

    @PostMapping("/add")
    @ApiOperation("广告图添加")
    public R<?> add(@RequestBody AdvImgCreateDTO advImgCreateDTO){
        yddAdvimgService.create(advImgCreateDTO);
        return R.success();
    }

    @GetMapping("/del")
    @ApiOperation("广告图删除")
    public R deleteById(@RequestBody Integer id){
        yddAdvimgService.deleteById(id);
        return R.success();
    }

    @GetMapping("/list")
    @ApiOperation("广告图列表-分页")
    public R<PageBean<YddAdvimg>> page(AdvImgPageDTO advImgPageDTO){
        PageBean<YddAdvimg> pageBean=yddAdvimgService.page(advImgPageDTO);
        return R.success(pageBean);
    }

    @GetMapping("/rowInfo")
    @ApiOperation("广告图详情")
    public R<AdvImgCreateDTO> rowInfoById(String id){
        AdvImgCreateDTO advImgCreateDTO=yddAdvimgService.rowInfoById(id);
        return R.success(advImgCreateDTO);
    }

    @PutMapping("/update")
    public R<?> updateById(@RequestBody AdvImgUpdateDTO advImgUpdateDTO){
        yddAdvimgService.updateById(advImgUpdateDTO);
        return R.success();
    }

}
